package com.yan.identitymanagement.severice;

import com.yan.identitymanagement.dao.Dao;
import com.yan.identitymanagement.domain.Civics;

import java.util.ListIterator;
import java.util.Scanner;

/**
 * @author taoge
 * @Date 2024/7/31 18:34
 * @Description
 */
public class SevericeImpl implements Severice{
    public static final Scanner INPUT = new Scanner(System.in);
    public static final Dao DAO = new Dao();

    @Override
    public void informationEntry() {
        Civics civics = new Civics();
        System.out.println("(1)请输入姓名:");
        String name = INPUT.next();
        civics.setName(name);
        System.out.println("(2)请输入身份证号码:");
        String id = INPUT.next();
        civics.setId(id);
        System.out.println("(3)请输入性别(1:男,0:女)");
        Integer i = INPUT.nextInt();
        if(i == 1){
            civics.setSex("男");
        }else{
            civics.setSex("女");
        }
        System.out.println("(4)请输入地址");
        String address = INPUT.next();
        civics.setAddress(address);
        DAO.deque.add(civics);
        System.out.println("录入成功！");
    }

    @Override
    public void informationQuery() {
        System.out.println("所有人的信息表如下");
        DAO.deque.forEach(item-> System.out.println(item));
    }

    @Override
    public void informationModification() {
        System.out.println("信息修改");
        System.out.println("请输入需要修改人身份证:");
        String newStr = INPUT.next();
        for (int i = 0; i < DAO.deque.size(); i++) {
            if (newStr.equals(DAO.deque.get(i).getId())) {
                System.out.println("开始修改信息:");
                System.out.println("请输入姓名:");
                String name = INPUT.next();
                DAO.deque.get(i).setName(name);
                System.out.println("请输入身份证号码:");
                String id = INPUT.next();
                DAO.deque.get(i).setId(id);
                System.out.println("请输入性别(1:男,0:女)");
                Integer j = INPUT.nextInt();
                if(j == 1){
                    DAO.deque.get(i).setSex("男");
                }else{
                    DAO.deque.get(i).setSex("女");
                }
                System.out.println("(4)请输入地址");
                String address = INPUT.next();
                DAO.deque.get(i).setAddress(address);
                System.out.println("信息修改成功！");
            }
        }
    }

    @Override
    public void informationDeletion() {
        System.out.println("开始信息删除");
        System.out.println("请输入删除的公民身份证号:");
        String newStr = INPUT.next();
        for (int i = 0; i < DAO.deque.size(); i++) {
            if (newStr.equals(DAO.deque.get(i).getId())) {
                System.out.println("开始删除");
                DAO.deque.remove(i);
                System.out.println("删除成功");
                return;
            }
        }
    }

}
